Ext.onReady(function(){
	   var showUrl = "/customer/signed/toView?id="+signedId+"&returnUrl=,marketing,pin,index&processFlag=processHistoryShow";
	   var tabKey = "sig_"+signedId;
	   var showHerf = "<a href='javascript:parent.openMenu(\"0\",\""+tabKey+"\",\"\",\"签约详情\",\""+showUrl+"\")' style='cursor:pointer'>签约明细</a>";
	   var d = new Date();
	   var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
	   var needReceiveRefundStore = new Ext.data.Store({
	    	fields:['id','receivablesFunds'],
	    	singleton:true,
	        autoDestroy:true,
		    proxy: {
		        type: 'ajax',
		        url: contextPath+'/marketing/proceeds/needDropDownList?relationId='+signedId,
		        reader: {
		            type: 'json',
		            root: 'root'
		        }
		    }
	   });
	   
	   needReceiveRefundStore.load({
		   callback:function(){
			  if(null!=needReceiveRefundId && needReceiveRefundId!=""){
				  Ext.getCmp("receivablesFundsId").setValue(parseInt(needReceiveRefundId));
			  }
		   }
	   });
		
		var fileAttachment = Ext.create('component.file.attachment',{
            objectId: '',
            imageType: "6",
            contextPath:contextPath,
            colspan:2
       });
		
		var hisAuditRecords = Ext.create('component.his.audit.records',{
			businessId: businessId,
			//延期签约编号: BusinessAbnormaEnum
			businessType: "12",
			showGrid: showGrid,
	        contextPath:contextPath,
	        colspan:2
	    });
		
	   var fromPanelInfo = Ext.create('Ext.form.FormPanel',{
		    renderTo:Ext.getBody(),
		    titleAlign:'center',
	        title:'应收款延期审批',
		    border: true,
		    layout:{
		    	 type: 'table',
                 columns: 2,
                 tableAttrs: {　　//在这儿控制table标签中的Attrs属性
                     border: 1,
                     cellpadding: 5,
                     cellspacing: 1,
                     width: '95%',
                     align: 'center',
                     style: "border:1px solid gray;border-collapse:collapse;margin:0 auto;text-align:center;"
                 },
                 tdAttrs: {　　//控制td标签的属性，以上用法都是在ext的api中查到，同样的方式可以给tr添加属性
                     width: '100px',
                     height: '40px',
                     style: "padding:5px",
                     valign: 'middle'
                 }
		    },
			 items:[{
				    xtype:'displayfield',
				    fieldLabel: '客户姓名',
				    name: 'customerName'
				},{
				    xtype:'displayfield',
				    fieldLabel: '房产名称',
				    name: 'roomName'
				},{
				    xtype:'displayfield',
				    fieldLabel: '房产类型',
				    name: 'propertyTypeName'
				},{
				    xtype:'displayfield',
				    fieldLabel: '计价面积(㎡)',
				    name: 'calculateArea'
				},{
				    xtype:'displayfield',
				    fieldLabel: '签约单价(元)',
				    name: 'signPrice'
				},{
				    xtype:'displayfield',
				    fieldLabel: '签约总价(元)',
				    name: 'signAmount'
				},{
				    xtype:'displayfield',
				    fieldLabel: '付款方式',
				    name: 'paymentMethodName'
				},{
				    xtype:'displayfield',
				    fieldLabel: '签约明细',
				    value:showHerf
				},{
                	xtype : 'combobox',
	                layout: "hbox",
	                name: "needReceiveId",
					fieldLabel : '应收款项',
			    	valueField: "id",
			    	displayField: "receivablesFunds",
			    	id:"receivablesFundsId",
					store: needReceiveRefundStore,
			    	blankText: "应收款项不能为空!",
			    	allowBlank: false,
			    	typeAhead: true,
		            //typeAhead:false, 
		            editable:false,
			    	listeners: {
				    	'change': function(value){
				    		//1、选中支付的款项
				    		//2、获取未收金额,并添加为收款的最大值
			    			var comboId = value.lastValue;
							Ext.Ajax.request({
								method: "POST",
								url: contextPath+"/marketing/needReceiveRefund/getNeedReceiveRefundInfo",
								params: {
									id:comboId
								},
								success: function(response, options){
									var jsonResult = Ext.decode(response.responseText);
									var result=Ext.JSON.decode(jsonResult.data);
									fromPanelInfo.getForm().setValues(result);
								},
								failure: function(response, options){
									Ext.Msg.alert('错误', '请求超时.');
								}
							});
							
							hisAuditRecords.loadNrrAuditRecord(value.lastValue);
			    		}
			    	}
            	},{
				    xtype:'displayfield',
				    fieldLabel: '应收日期',
				    name: 'receivablesDate',
				    id:"receivablesDate"
				},{
				    xtype:'displayfield',
				    fieldLabel: '应收金额(元)',
				    name: 'totalReceivablesAmount'
				},{
				    xtype:'displayfield',
				    fieldLabel: '已收金额(元)',
				    name: 'haveReceivedTotal'
				},{
				    xtype:'displayfield',
				    fieldLabel: '已申请延期天数',
				    name: 'delayDayCount'
				},{
				    xtype:'displayfield',
				    fieldLabel: '延期开始日期',
				    name: 'delayStartDay'
				},{
				    xtype:'datefield',
				    fieldLabel: '延期结束日期',
				    allowBlank:false,
			    	blankText:'不能为空',
			    	format: 'Y-m-d',
			    	id:'delayDate',
			    	listeners : {
				    	'select' : function(m, d) {
				    		 var endE=Ext.util.Format.date(m.value,'Y-m-d');
				    		 var receivablesDate=Ext.getCmp("receivablesDate").getValue();
				    		 var startE=Ext.util.Format.date(receivablesDate,'Y-m-d');
				    		 var end = new Date(endE);  
				             var start = new Date(startE); 
				    		 var sjjdpc = Math.round((end.getTime()-start.getTime()) / (86400000));
				    		 Ext.getCmp("delayShowDay").setValue(sjjdpc+"天");
				    	}
				    }
				},{
				    xtype:'displayfield',
				    fieldLabel: '延期天数',
				    name: 'delayShowDay',
				    id:'delayShowDay'
				},{
				    xtype:'textarea',
				    fieldLabel: '延期原因',
				    name: '',
				    width:780,
				    align: 'left',
				    id:'reason',
				    colspan:2,
				    maxLength:255,
				    allowBlank:false,
			    	blankText:'不能为空'
				},{
				    xtype:'displayfield',
				    fieldLabel: '经纪人',
				    name: 'userName'
				},{
				    xtype:'displayfield',
				    fieldLabel: '申请日期',
				    value: str
				},hisAuditRecords,fileAttachment],
				dockedItems: [{
		            xtype: 'toolbar',
		            dock: 'bottom',
		            ui: 'footer',
		            layout: {
		                pack: 'center'
		            },
		            items: [{
		                minWidth: 80,
		                text: '提交审核',
		                id:'save_button',
		                iconCls:'icon-save',
		                handler:function(){
		                	var form = fromPanelInfo.getForm();
		                	var fileUrlArr =fileAttachment.getFileArrs();
		                	if(form.isValid()){
		                		var params={
			                		signedId:signedId,
			                		needReceiveRefundId:Ext.getCmp("receivablesFundsId").getValue(),
			                		remark:Ext.getCmp("reason").getValue(),
			                	    delayDate:Ext.getCmp("delayDate").getValue(),
			                	    fileUrlArr:fileUrlArr,
		                			imageType: "6",
		                			'token':token
			                	};
		                		Ext.Ajax.request({
			                		url:contextPath+'/customer/signed/submitDeferredPayment',
			                		params:params,
			                		callback: function (options, success, response) {
			                			 var obj = JSON.parse(response.responseText);
			                			 if(obj.res=="1"){
			                				 Ext.MessageBox.alert("系统提示", "保存成功! ", function(but) {  
			                					 var tabKey = "def_"+signedId;
			    								 parent.TabControlRemove(tabKey);
		    				                });  
			                				 
			    						 }else{
			    							 Ext.MessageBox.alert("系统提示",obj.resMsg); 
			    						 }
			                		}
			                	});
		                		
		                	}
		                }
		            },
		            {
						xtype: "button",
						text : "返回",
						id: "btn_back",
						name: "btn_back",
						icon : contextPath + '/resources/ExtJSicons/shape_move_backwards.png',
						listeners: {
							click: function(){
								 var tabKey = "def_"+signedId;
								 parent.TabControlRemove(tabKey);
							}
						}
					}]
		        }
		        ]
	   });
	   
	   fromPanelInfo.getForm().load({
			url:contextPath+'/customer/signed/loadDeferredPaymentInfo',
			params:{'signedId':signedId},
			success:function(form, action){
				var obj = action.result.data;
				var result=Ext.JSON.decode(obj);
				fromPanelInfo.getForm().setValues(result);
			},   
			failure: function(form, action) {
		        Ext.Msg.alert("加载失败", action.result.errorMessage);
		    }

		});
	  
});